using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace YYJ.UI {
    public partial class LoginForm : BaseForm {
        public LoginForm() {
            InitializeComponent();

            txtUser.Text = "admin";
            txtPwd.Text = "admin";
        }

        private void btnOK_Click( object sender, EventArgs e ) {
            if( YYJ.Entities.User.validate( txtUser.Text, txtPwd.Text ) ) {
                this.switchTo<MainForm>();
            } else {
                //lblMessage.Visible = true;
                this.displayLabelForAWhile( lblMessage, 6000 );

                txtUser.Focus();
                txtUser.SelectAll();
                btnOK.Enabled = false;
            }
        }

        private void txtUser_TextChanged( object sender, EventArgs e ) {
            updateControls();
        }

        private void txtPwd_TextChanged( object sender, EventArgs e ) {
            updateControls();
        }

        private void updateControls() {
            btnOK.Enabled = txtUser.Text.Trim().Length > 0 && txtPwd.Text.Trim().Length > 0;
            if( lblMessage.Visible ) {
                lblMessage.Visible = !btnOK.Enabled;
            }
        }

        private void btnCancel_Click( object sender, EventArgs e ) {
            this.Close();
        }
    }
}